<?php
	require 'libraries/GetClientLib.php';
	require 'libraries/PaymentLib.php';
	require 'libraries/UserLibrary.php';
	require 'libraries/CreateReportLib.php';
	
	isSessionSet("administrator", null, "index.php");
	
	$client = getClientInformation($_GET['sample_key'],'casl','localhost','login','login');
	$dates = getCaslMinMax($_GET['sample_key'],'casl','localhost','login','login');
	$status = getStatus($_GET['sample_key'],'casl','localhost','login','login');
	
	if(!ClientExists($_GET['sample_key'],'casl','localhost','login','login')){
		echo "<h3>Sorry, We could not find an analysis with those details.</h3>";
	}
	else{
?>
<html>
	<head>
		<title>CASLIMS | Summary</title>
		<link rel="stylesheet" type="text/css" href="scripts/page.css"/>
		<link href="tools/favicon.ico" rel="shortcut icon" type="image/x-icon" /> 
	</head>
	</body>
		<div id="header"></div>
		<div id="wrapper">
			<div id="pagetop">
				<div class="greeting">Hi, <?php echo $_SESSION["administrator"];?> | <a href="Logout.php">Log out</a>  | <a href="AdministratorHomepage.php"> Home </a></div>
				<div class="homepage"><?php echo $_SESSION["administrator"];?></div>
			</div>
		<h2>ANALYSIS SUMMARY</h2>
		<table border="0">
			<tr>
				<td><h3>CLIENT INFORMATION</h3></td>
				<td></td>
			</tr>
			<tr>
				<td>Name of Representative</td>
				<td><?php echo $client['name']; ?></td>
			</tr>
			<tr>
				<td>Company</td>
				<td><?php echo $client['company']; ?></td>
			</tr>
			<tr>
				<td>Address</td>
				<td><?php echo $client['address']; ?></td>
			</tr>
			<tr>
				<td>Contact Details</td>
				<td>Fax:</td>
				<td><?php echo $client['fax']; ?></td>
			</tr>	
			<tr>
				<td></td>
				<td>Tel. No:</td>
				<td><?php echo $client['tel_no']; ?></td>
			</tr>
			<tr>
				<td></td>
				<td>Email Ad: </td>
				<td><?php echo $client['email']; ?></td>
			</tr>
			<tr>
				<td></td>
				<td>Cell No.:</td>
				<td> <?php echo $client['cell_no']; ?></td>																	
			</tr>
		</table>		
		<table border = "0">	
			<tr>
				<td><h3>ANALYSIS INFORMATION</h3></td>
			</tr>
			<tr>
				<td>Date Submitted: </td>
				<td><?php echo $client['date_created']; ?></td>
			</tr>
			<tr>
				<td>CASL Lab No(s): </td>
				<td><?php printf("%04d, %04d-%04d",$dates['casl_no_year'],$dates['minimum'],$dates['maximum']);?> </td>
			</tr>
		</table>
		<br/>
		<table>
			<thead>
			<tr>
				<th>Analysis Required</th>
				<th>Cost/Analysis</th>
				<th>No. of Samples</th>
				<th>Total Cost</th>
			</tr>
			</thead>
			<?php $samples = getSamples($_GET['sample_key'],'casl','localhost','login','login');
			$totalvalue = 0;
			for($i = 0; $i < count($samples); $i++){
				echo "<tr>";
				echo "<td>".$samples[$i]['analysis_required']."</td>";
				echo "<td>".$samples[$i]['cost']."</td>";
				echo "<td>".$samples[$i]['count']."</td>";
				echo "<td>".$samples[$i]['total']."</td>";
				$totalvalue += $samples[$i]['total'];
				echo "</tr>";
			}
			echo "<tr>";
				echo "<td></td>";
				echo "<td></td>";
				echo "<td>Total Cost </td>";
				printf( "<td>%10.2f </td>",$totalvalue);
			
			echo "</tr>";
			?>
		</table>
		<br/>
		<table>
			<thead>
			<tr>
				<th>Sample Code</th>
				<th>CASL Number</th>
				<th>Analysis</th>
				<th>Mean</th>
				<th>Standard Deviation</th>
				<th>Unit</th>
			</tr>
			</thead>
			<?php
			$results = GetInformation($_GET['sample_key'],'casl','localhost','login','login');
			for($i = 0; $i < count($results); $i++){
				echo "<tr>";
				echo "<td>".$results[$i][0]."</td>";
				echo "<td>".sprintf("%04d-%04d",$results[$i][1],$results[$i][2])."</td>";
				echo "<td>".$results[$i][3]."</td>";
				echo "<td>".$results[$i][4]."</td>";
				echo "<td>".$results[$i][5]."</td>";
				echo "<td>".$results[$i][6]."</td>";
				echo "</tr>";
			}
			?>
		</table>
		<table>
			<tr>
				<td>
					<?php $paymentinfo = paymentInfo($_GET['sample_key'],'casl','localhost',
					'login','login','payment');
		
					if(strcmp($paymentinfo['payment_mode'],"CHECK")==0){
						echo "Payment into Deposit ".$paymentinfo['bank'] ." ". $paymentinfo['date']. " - OFFICIAL RECEIPT NUMBER " .$paymentinfo['official_receipt_num'];
					}
					else{
						echo "Payment into Deposit ". $paymentinfo['date']. "- OFFICIAL RECEIPT NUMBER " .$paymentinfo['official_receipt_num'];
					}
					?>
				</td>
			</tr>
		</table>
			<form name="ChangeStat" action='ProcessStatus.php?sample_key=<?php echo $_GET["sample_key"];?>' method="post" onsubmit="true">
				<div id="buttons">
					<?php 
					
					if ($status[0]!="Finalized"){
						echo "Status: ";
						echo '<select name="status" >
							<option value="Ongoing">Ongoing</option>
							<option value="Endorsed">Endorsed</option>
							<option value="Finalized">Finalized</option>
							</select>
						<input type="submit" name="changestat" value="Change Status" />';									
					}
					
					?>
					<input type="button" value="View Final Report" onClick='document.location.href = "ProcessViewReport.php?sample_key=<?php echo $_GET["sample_key"];?>"'/>
				</div>
			</form>
			
			<div id="footerwrap">
				<div id="footer"> 
					<div class="copyright">Copyright 2011.<a>CASL BIOTECH-UPLB.</a> All Rights Reserved.<br/> 
				Arianne Buse&ntilde;os | Darlene Joy Masong | Rick Jason Obrero | Jonathan Pandi | Jonathan Simbahan | Emmanuel Soriano 
					</div> 
	    	    </div>
			</div>		
        </div>		
	</body>
</html>
<?php }
?>